<?php if (!defined('BASEPATH')) exit('Sorry, error.. :]');

	class Treelib {
	
		var $CI;
		
		function __construct()
		{
			$this->CI = &get_instance();
		}
		
		public function get($id, $table)
		{
            return $this->get_child($id, $table);
		}
		
		private function get_child($id, $table)
		{
			$arr = array();
				if ($arr = Doctrine_Query::create()->from($table)->where('parent_id ='.$id)->orderBy('orders')->fetchArray()) {
					foreach ($arr as $key => $val) {
                        $arr[$key]['count'] = Doctrine::getTable('Photos')->PhotoByCat($val['id'])->count();
						$arr[$key]['parent'] = $this->get_child($val['id'], $table);
					}
				}
				
			return $arr;
		}
	}